<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	protected function _initView()
    {
        // Initialize view
        $view = new Zend_View();
        $view->doctype('XHTML1_STRICT');
        $view->headTitle('Backend CMS');
        
        // Add it to the ViewRenderer
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
            'ViewRenderer'
        );
        $viewRenderer->setView($view);

        // Return it, so that it can be stored by the bootstrap
        return $view;
    }
    
    public function _initConfig()
    {
    	$this->bootstrap('db');
    	$this->_config = array();
    	
    	$select = $this->getResource('db')->select();
    	$select->from('bcms_config', array('option', 'value'));

		$this->_config = $this->getResource('db')->fetchPairs($select);

    	return $this->_config;
    }
    
    public function _initLog()
    {
    	$this->bootstrap('frontcontroller');
    	$log = new Zend_Log();

    	$writer = new Zend_Log_Writer_Firebug();
    	$log->addWriter($writer);

    	if($writer instanceof Zend_Log_Writer_Firebug) {
    		$writer-> setPriorityStyle(8, 'TABLE');
    		$log->addPriority('TABLE', 8);
    	}
    	
    	$this->bootstrap('translate');
    	
    	$translate = $this->getResource('translate');
    	
    	$translator = $translate->getAdapter();
    	$translator->setOptions(array(
    		'log'				=>	$log,
    		'logUntranslated'	=>true
    	));

    	/*
    	 * Set _logger for use with other methods
    	 */
    	$this->_log = $log;
    	
    	return $log;
    }
    
    protected function _initModuleAutoloader()
    {
    	$autoloader = new Zend_Application_Module_Autoloader(array(
    		'namespace'	=>	'Bcmsx_',
    		'basePath'	=>	APPLICATION_PATH
    	));

    	Zend_Controller_Action_HelperBroker::addPath( APPLICATION_PATH . '/helpers', 'Bcmsx_Action_Helper' );

    	return $autoloader;
    }
    
    protected function _initMenu()
    {
    	$pages = new Zend_Config_Ini(APPLICATION_PATH . '/configs/pages.ini', 'mainmenu');

    	$container = new Zend_Navigation($pages);
    	
    	return $container;
    }
    /*
    protected function _initDb()
    {
    	if($this->hasPluginResource('db')){
    		$db = $this->getPluginResource('db');
    		$db->getDbAdapter()->setFetchMode(Zend_Db::FETCH_OBJ);
    	}
    }
*/
}